<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>广告位管理</title>
    {sys:load href="admin/css/bootstrap.min.css,admin/css/materialdesignicons.min.css,admin/css/animate.css,admin/css/style.min.css,admin/js/bootstrap-table/bootstrap-table.min.css,admin/lib/layui/css/layui.css"}

</head>

<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header"><h4>广告位列表</h4></div>
                <div class="card-body">

                    <div id="toolbar" class="toolbar-btn-action">
                        <form class="form-inline" action="lyear_forms_elements.html" method="post" onsubmit="return false;">
                            <div class="form-group">
                                <label class="sr-only" for="keyword">关键字</label>
                                <input class="form-control" type="text" id="keyword" name="keyword" placeholder="" autocomplete="off">
                            </div>
                            <div class="form-group">
                                <button class="btn btn-cyan" type="submit" id="btn-search">检索</button>

                                <button type="button" class="btn btn-primary m-r-5" onclick="openModel('新增广告位', '/app/cms/admin.advert/savepos')">
                                    <span class="mdi mdi-plus" aria-hidden="true"></span>新增
                                </button>

                                <button type="button" class="btn btn-primary m-r-5" onclick="loadSelf()"><span class="mdi mdi-rotate-3d" aria-hidden="true"></span>刷新</button>
                            </div>
                        </form>
                    </div>
                    <table id="tb_position"></table>

                </div>
            </div>
        </div>

    </div>

    {sys:load href="admin/lib/layui/layui.js,admin/common.js,admin/js/jquery.min.js,admin/js/bootstrap.min.js,admin/js/perfect-scrollbar.min.js,admin/js/bootstrap-table/bootstrap-table.js,admin/js/bootstrap-table/bootstrap-table-zh-CN.min.js"}

    <script type="text/html" id="operate">
        <a href="javascript:openModel('编辑{{d.title}}', '/app/cms/admin.advert/savepos?id={{d.id}}')" class="btn btn-xs btn-default m-r-5" title="修改" data-toggle="tooltip"><i class="mdi mdi-pencil"></i>修改</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:multitabs('管理{{d.title}}', '/app/cms/admin.advert/index?pos_id={{d.id}}');" class="btn btn-xs btn-default" title="管理"><i class="mdi mdi-console-line"></i>管理</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:del({{d.id}})" class="btn btn-xs btn-default" title="删除"><i class="mdi mdi-window-close"></i>删除</a>
    </script>

    <script type="text/html" id="thumb">
        <img src="{{d.thumb}}" style="width: 100px" />
    </script>

    <script type="text/javascript">
        layui.use(['layer', 'jquery', 'Request','table'], function(){
            var Request = layui.Request , table = layui.table, $ = layui.jquery;

            let dataTableIndex = table.render({
                elem: '#tb_position'
                ,url:'/app/cms/admin.advert/listpos'
                ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                ,parseData: function(res){ //res 即为原始返回的数据
                    return {
                        "code": res.state == 'success' ? 0 : -1, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.total, //解析数据长度
                        "data": res.rows //解析数据列表
                    };
                }
                ,cols: [[
                    {field: 'check', type: 'checkbox'}
                    ,{field:'id', width:80, title: 'ID', sort: true}
                    ,{field:'title', width:280, title: '广告位名称'}
                    ,{field:'desc', width:480, title: '广告位说明'}
                    ,{field: 'create_time', title: '创建时间', width: 200}
                    ,{field:'operate', title: '操作',  templet: '#operate'}
                ]],page: true
            });

            $("#btn-search").on('click', function(){
                dataTableIndex.reload({
                    where:{keyword: $("#keyword").val()}
                })
            })
        })

        function del(id)
        {
            layui.use(['layer','Request'], function(){
                var layer = layui.layer,request = layui.Request;
                request.get('/app/cms/admin.advert/delpos',{id:id}, function(response){
                    layer.msg('成功删除', {time: 1000}, function(){
                        window.location.reload()
                    })
                })
            })
        }
    </script>
</body>
</html>
